﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KCMS.DataAcsess.Interfaces;
using StructureMap;
using AutoMapper;
using KCMS.BusinessLogic.Models;
using KCMS.BusinessLogic.Interfaces;


namespace KCMS.BusinessLogic.Engine
{
    public class BrendService:IBrendService
    {
        private IBrendManager brendManager = ObjectFactory.GetInstance<IBrendManager>();
        public Models.Brend getById(Guid id)
        {
            DataAcsess.Entitys.BrendEntity brendEntity = brendManager.getById(id);
            return Mapper.Map<DataAcsess.Entitys.BrendEntity, Models.Brend>(brendEntity);
        }
       
        public IEnumerable<Models.Brend> getAll()
        {
            var model = from t in brendManager.getAll()
                        orderby t.Title
                        select t;
            return Mapper.Map<IEnumerable<DataAcsess.Entitys.BrendEntity>, IEnumerable<Models.Brend>>(model);

        }

        public void update(Brend brend)
        {
            brendManager.update(Mapper.Map<Brend, DataAcsess.Entitys.BrendEntity>(brend));
        }


        public void save(Brend brend)
        {
            brendManager.save(Mapper.Map<Brend, DataAcsess.Entitys.BrendEntity>(brend));
        }


        public void delete(Guid id)
        {
            brendManager.delete(id);
        }


        public Brend getByCode(string code)
        {
            return (from t in getAll()
                    where t.Code.Equals(code)
                    select t).SingleOrDefault();
        }
    }
}
